<?php
namespace app\common\exception;
use think\Exception;

/**
* 异常类的基类
*/
class BaseException extends Exception
{
	protected $code 		= 500;
	protected $message      = '系统开小差儿。。。';
	protected $errorCode	= 0;
	protected $info 		= [
		'系统开小差儿。。。'
	];

    /**
     * 异常基类 实例化必须传入数组
     * BaseException constructor.
     * @param array $params
     */
	public function __construct($errorCode = 0, $code = null)
	{
		if (array_key_exists($errorCode, $this->info) && !empty($this->info[$errorCode])) {
			$this->message  = $this->info[$errorCode];
			$this->errorCode = $errorCode;
		} else {
			$this->message  = $this->info[0] ?? '系统开小差儿。。。';
			$this->errorCode = 0;
		}

		if (!empty($code)) {
			$this->code = $code;
		}

    }

    /**
     * 外部获取错误码方法
     * @return int
     */
    public function getErrorCode(): int
    {
        return $this->errorCode;
    }
}